/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS变量定义 */
:root {
    --primary-color: #10b981;
    --primary-light: #34d399;
    --primary-dark: #059669;
    --secondary-color: #065f46;
    --background-color: #f0fdf4;
    --surface-color: #ffffff;
    --text-primary: #064e3b;
    --text-secondary: #6b7280;
    --border-color: #d1fae5;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --success-color: #10b981;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --box-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* 基础字体和布局 */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background-color);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* 头部样式 */
.header {
    background: var(--surface-color);
    box-shadow: var(--box-shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.logo i {
    font-size: 2rem;
}

.nav {
    display: flex;
    gap: 1rem;
}

.nav-btn {
    padding: 0.5rem 1.5rem;
    border: 2px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.nav-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* 主内容区域 */
.main {
    padding: 2rem 0;
    min-height: calc(100vh - 140px);
}

.mode-section {
    display: none;
}

.mode-section.active {
    display: block;
}

/* 上传区域样式 */
.upload-area {
    background: var(--surface-color);
    border: 3px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    margin-bottom: 2rem;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(16, 185, 129, 0.05);
}

.upload-content {
    max-width: 400px;
    margin: 0 auto;
}

.upload-icon {
    font-size: 4rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    display: block;
}

.upload-area h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.file-types {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.upload-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 1rem;
}

.upload-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--box-shadow);
}

/* 选项面板样式 */
.options-panel,
.batch-options {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--box-shadow);
    margin-bottom: 2rem;
}

.options-panel h3,
.batch-options h3 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.options-grid,
.batch-options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.option-group label {
    font-weight: 600;
    color: var(--text-primary);
}

.quality-slider {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.quality-slider input[type="range"] {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.quality-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
}

.quality-slider input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.quality-value {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 40px;
}

.quality-presets {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.preset-btn {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.3s ease;
}

.preset-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.preset-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

select {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.compress-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.125rem;
    font-weight: 600;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 auto;
}

.compress-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-lg);
}

.compress-btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
}

.compress-btn.loading i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 结果展示区域 */
.result-section,
.batch-results {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--box-shadow);
}

.result-section h3,
.batch-results h3 {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
    text-align: center;
}

.comparison-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 2rem;
    align-items: center;
}

.image-card {
    background: var(--background-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    text-align: center;
}

.image-card h4 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.image-preview {
    background: white;
    border-radius: var(--border-radius-sm);
    padding: 1rem;
    margin-bottom: 1rem;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
}

.image-preview img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--border-radius-sm);
}

.image-info {
    text-align: left;
}

.image-info p {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.image-info span:first-child {
    color: var(--text-secondary);
}

.image-info span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

.compression-arrow {
    text-align: center;
    color: var(--primary-color);
}

.compression-arrow i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.compression-ratio {
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    font-size: 1.125rem;
}

.download-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem auto 0;
}

.download-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

/* 批量处理结果样式 */
.batch-summary {
    background: var(--background-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    align-items: center;
}

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.summary-item span:first-child {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.summary-item span:last-child {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.125rem;
}

.download-all-btn {
    grid-column: 1 / -1;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.125rem;
    font-weight: 600;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem auto 0;
    max-width: 300px;
}

.download-all-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-lg);
}

.batch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.batch-item {
    background: var(--background-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    text-align: center;
    border: 1px solid var(--border-color);
}

.batch-item img {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 1rem;
}

.batch-item-info {
    text-align: left;
    margin-bottom: 1rem;
}

.batch-item-info p {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.batch-item-info span:first-child {
    color: var(--text-secondary);
}

.batch-item-info span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

.batch-item-ratio {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    display: inline-block;
    margin-bottom: 1rem;
}

/* 加载遮罩 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    background: white;
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    box-shadow: var(--box-shadow-lg);
}

.loading-spinner i {
    font-size: 3rem;
    color: var(--primary-color);
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
    display: block;
}

.loading-spinner p {
    color: var(--text-primary);
    font-size: 1.125rem;
}

/* Toast 通知 */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-lg);
    display: none;
    align-items: center;
    gap: 0.75rem;
    max-width: 400px;
    z-index: 1001;
}

.toast.show {
    display: flex;
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--error-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

.toast i {
    font-size: 1.25rem;
}

.toast.success i {
    color: var(--success-color);
}

.toast.error i {
    color: var(--error-color);
}

.toast.warning i {
    color: var(--warning-color);
}

/* 页脚 */
.footer {
    background: var(--surface-color);
    padding: 2rem 0;
    text-align: center;
    color: var(--text-secondary);
    margin-top: auto;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }

    .header .container {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem 15px;
    }

    .logo {
        font-size: 1.25rem;
    }

    .logo i {
        font-size: 1.5rem;
    }

    .nav {
        width: 100%;
        justify-content: center;
    }

    .nav-btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .upload-icon {
        font-size: 3rem;
    }

    .options-grid,
    .batch-options-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .comparison-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .compression-arrow {
        order: -1;
    }

    .compression-arrow i {
        transform: rotate(90deg);
        font-size: 1.5rem;
    }

    .batch-summary {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .batch-grid {
        grid-template-columns: 1fr;
    }

    .quality-presets {
        justify-content: center;
    }

    .preset-btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.8rem;
    }

    .toast {
        right: 15px;
        left: 15px;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .upload-area {
        padding: 1.5rem 1rem;
    }

    .upload-area h3 {
        font-size: 1.25rem;
    }

    .options-panel,
    .batch-options,
    .result-section,
    .batch-results {
        padding: 1.5rem;
    }

    .compress-btn {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    .image-preview {
        min-height: 150px;
    }

    .image-preview img {
        max-height: 200px;
    }
}

/* 对比功能样式 */
.comparison-controls {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.view-toggle-btn {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.3s ease;
}

.view-toggle-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.view-toggle-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* 滑动对比样式 */
.slider-comparison-view {
    background: var(--background-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
}

.slider-container h4 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    text-align: center;
}

.image-slider-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    max-width: 100%;
    margin: 0 auto;
    max-height: 500px;
    background: white;
    width: 100%;
    height: 500px;
}

.image-slider-wrapper img {
    display: block;
    position: absolute;
    object-fit: contain;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

#slider-original {
    z-index: 1;
}

.slider-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.slider-overlay img {
    clip-path: inset(0 50% 0 0); /* 初始只显示右半部分 */
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.slider-divider {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 100%;
    background: var(--primary-color);
    cursor: grab;
    z-index: 10;
    transition: background-color 0.3s ease, width 0.3s ease;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.1);
}

.slider-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    color: var(--primary-color);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--primary-color);
    z-index: 11;
    transition: all 0.3s ease;
}

.slider-divider:hover .slider-button {
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.slider-info {
    margin-top: 1rem;
    text-align: center;
}

.info-section {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.875rem;
}

.info-section span {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.info-section span:first-child {
    color: var(--text-secondary);
    font-weight: normal;
}

.info-section span:last-child {
    color: var(--text-primary);
    font-weight: 600;
}

/* 叠加对比样式 */
.overlay-comparison-view {
    background: var(--background-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
}

.overlay-container h4 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    text-align: center;
}

.image-overlay-comparison {
    position: relative;
    max-width: 100%;
    margin: 0 auto;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.image-overlay-comparison img {
    width: 100%;
    height: auto;
    display: block;
    max-height: 400px;
    object-fit: contain;
}

.image-overlay-comparison img:first-child {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.image-overlay-comparison img:last-child {
    position: relative;
    z-index: 2;
    transition: opacity 0.3s ease;
}

.opacity-slider {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--surface-color);
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: center;
}

.opacity-slider label {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.opacity-slider input[type="range"] {
    flex: 1;
    max-width: 200px;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.opacity-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
}

.opacity-slider input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

#opacity-value {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 40px;
}

/* 响应式对比功能 */
@media (max-width: 768px) {
    .comparison-controls {
        flex-direction: column;
        align-items: center;
    }

    .view-toggle-btn {
        width: 100%;
        max-width: 200px;
    }

    .info-section {
        flex-direction: column;
        align-items: center;
    }

    .opacity-slider {
        flex-direction: column;
        gap: 0.5rem;
    }

    .opacity-slider input[type="range"] {
        max-width: 150px;
    }

    .image-slider-wrapper img,
    .image-overlay-comparison img {
        max-height: 300px;
    }

    .slider-button {
        width: 28px;
        height: 28px;
        font-size: 0.875rem;
    }

    .slider-divider {
        width: 3px;
    }
}

@media (max-width: 480px) {
    .slider-overlay img,
    .image-slider-wrapper img,
    .image-overlay-comparison img {
        max-height: 250px;
    }

    .slider-button {
        width: 24px;
        height: 24px;
        font-size: 0.75rem;
    }

    .slider-divider {
        width: 2px;
    }

    .opacity-slider {
        padding: 0.75rem;
    }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #022c22;
        --surface-color: #064e3b;
        --text-primary: #ecfdf5;
        --text-secondary: #a7f3d0;
        --border-color: #047857;
    }

    body {
        background-color: var(--background-color);
        color: var(--text-primary);
    }

    .upload-area {
        background: var(--surface-color);
    }

    .image-card,
    .batch-item,
    .batch-summary {
        background: var(--surface-color);
        border-color: var(--border-color);
    }

    .image-preview {
        background: var(--background-color);
        border-color: var(--border-color);
    }

    .loading-spinner {
        background: var(--surface-color);
    }

    .toast {
        background: var(--surface-color);
        color: var(--text-primary);
    }

    .slider-comparison-view,
    .overlay-comparison-view {
        background: var(--surface-color);
    }

    .opacity-slider {
        background: var(--background-color);
    }

    .slider-button {
        background: var(--surface-color);
        color: var(--primary-color);
    }
}